package com.freesky.web.manager.controller;

import com.freesky.common.pojo.KindEditorResult;
import com.freesky.common.utils.QiniuUtil;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.manager.remote.ImageRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @author Freesky
 */
@RestController
@Api(description = "图片上传统一接口")
public class ImageController {

    @Autowired
    private ImageRemote imageRemote;

    @RequestMapping(value = "/image/imageUpload", method = RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ApiOperation(value = "WebUploader图片上传")
    public JSONResponse uploadFile(@RequestPart("file") MultipartFile files) {
        return imageRemote.uploadFile(files);
    }

    @PostMapping(value = "/kindeditor/imageUpload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ApiOperation(value = "KindEditor图片上传")
    public KindEditorResult kindEditor(@RequestParam("imgFile") MultipartFile files) {
        return imageRemote.kindEditor(files);
    }
}
